﻿using oop4;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MyContact
{
    public partial class AddNewContacts : Form
    {
        private List<Contact> contacts;
        private ListBox listBox;
        public AddNewContacts()
        {
            InitializeComponent();
        }
        public AddNewContacts(ref List<Contact> contacts, ListBox listBox1)
        {
            InitializeComponent();
            this.contacts = contacts;
            listBox = listBox1;
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            //确认添加联系人:
            string name = textBox1.Text;
            string tel = textBox2.Text;
            string address = textBox3.Text;
            Contact contact = new Contact();
            contact.Name = name;
            contact.PhoneNumber = tel;
            contact.Address = address;
            //
            contacts.Add(contact);
            listBox.Items.Add(contact.Name);
            
            MessageBox.Show("添加联系人成功了!");
        }

        private void button2_Click(object sender, EventArgs e)
        {
            //退出:
            DialogResult result = MessageBox.Show("是否退出 ?", "警告",
                                                  MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
            if (result == DialogResult.OK)
            {
                Dispose();
            }

        }

        private void AddNewContacts_Load(object sender, EventArgs e)
        {

        }
    }
}
